﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using ProjectBase.Core;
using ProjectBase.Core.Web;
using ProjectBase.Mvc;
using ProjectBase.Mvc.Controllers;
using Survey.Common;
using Survey.Common.Business;
using Survey.Common.Controllers;
using Survey.Common.Models;
using Survey.Entity;

namespace Survey.Controllers
{
    /// <summary>
    /// All actions for Question
    /// </summary>
    public class QuestionController : EntityController<Question, QuestionFilter, IQuestionModel, IQuestionFacade>, IQuestionController
    {
        #region OnList

        /// <summary>
        /// Provides columns for List view
        /// </summary>
        protected override IEnumerable<IItemToDisplay> LoadItemsToDisplay(QuestionFilter filter)
        {
            return Facade.Find(filter)
                .Select(i => new ItemToDisplay()
                {
                    ID = i.IDToDisplay,
                    Description = i.ToDisplay(),
                    Items = new List<ICellDescription>
                    {
                        i.Cell(() => i.Title),
                        i.Cell(() => i.Description),
                        i.Cell(() => i.IsApproved),
                        i.Cell(() => i.ValidUntil),
                        i.Cell(() => i.ID, new CellDescription {Align = Align.right, Format = "N0"}),
                    }
                } as IItemToDisplay);
        }

        /// <summary>
        /// Provides columns for Excel
        /// </summary>
        protected override IEnumerable<IEnumerable<IExCell>> LoadExcelItemsToDisplay(QuestionFilter filter)
        {
            return Facade.Find(filter)
                    .Select(i => new List<IExCell>
                    {
                        i.ExCell(() => i.ID),
                        i.ExCell(() => i.Title),
                        i.ExCell(() => i.IsApproved),
                        i.ExCell(() => i.ValidUntil),
                        i.ExCell(() => i.Description),
                    });
        }

        #endregion OnList

        #region OnBefore

        #endregion OnBefore

        #region Actions

        #endregion Actions

        #region abstract ClearSearchParam

        /// <summary>
        /// Resets values of filtering object to default
        /// </summary>
        protected override QuestionFilter ClearFilter()
        {
            var filter = base.ClearFilter();

            // TODO set the MVC defaults e.g.: filter.OrderBy["ID"] = false;
            return filter;
        }

        #endregion abstract ClearSearchParam

        #region properties

        public override string ControllerName { get { return Str.Controllers.Question; } }

        // TODO:
        // e.g. IUserFacade if User instance is needed:
        // NOTE
        // if 'Project.config' file factoryType is set:
        // value="ProjectBase.Data.Factory.IocWithProxyFactory, ProjectBase.Data
        // implementor of the 'IFacade' will be injected for you: LAZILY!

        // public virtual IUserFacade UserFacade { protected get; set; }

        #endregion properties
    }
}